package com.gitee.zycra.future.job.common.vo;

import com.gitee.zycra.future.job.common.model.JobUser;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

/**
 * @author zycra
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class JobUserVO {

    /**
     * 主键
     */
    private Long id;

    /**
     * 用户名
     */
    private String username;

    /**
     * 权限
     * @see com.gitee.zycra.future.job.common.enums.UserAuthEnum
     */
    private Integer auth;

    /**
     * 是否启用
     */
    private Boolean enabled;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 上次尝试登录时间
     */
    private LocalDateTime lastLoginTime;

    public static JobUserVO buildJobUserVO(JobUser jobUser) {
        if (jobUser == null) {
            return null;
        }
        return new JobUserVO().setId(jobUser.getId())
                .setUsername(jobUser.getUsername())
                .setAuth(jobUser.getAuth())
                .setEnabled(jobUser.getEnabled())
                .setCreateTime(jobUser.getCreateTime())
                .setUpdateTime(jobUser.getUpdateTime())
                .setLastLoginTime(jobUser.getLastLoginTime());
    }
}
